﻿@using DataMongo
@model IEnumerable<DataMongo.Entities.FeedPost>
@{
    ViewBag.Title = "Feed Post";
}
<div class="row">
    <div class="col-lg-12">
        <h2>Feed List</h2>
        <p>
            @Html.ActionLink("Create", "FeedPostAdd", "SuperAdmin", "", new { @class = "btn btn-info" })
            <a class="btn btn-info generateFeeds" href="javascript:void(0)">Generate Feeds</a>
        </p>
        <div class="table-responsive feedlistTable">
            <table class="table table-bordered table-hover table-striped tablesorter" style="font-size:12px;">
                <thead>
                    <tr>
                        <th>Title <i class="fa fa-sort"></i></th>
                        <th width="30%">Description <i class="fa fa-sort"></i></th>
                        <th width="10%">Source <i class="fa fa-sort"></i></th>
                        <th>Category<i class="fa fa-sort"></i></th>
                        <th>Image<i class="fa fa-sort"></i></th>
                        <th>Source Link<i class="fa fa-sort"></i></th>
                        <th width="20%">

                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model.OrderByDescending(x => x.IsUpcoming))
                    {
                        <tr>
                            <td>@item.Title</td>
                            <td>@Html.Raw(item.ShortDescription)</td>
                            <td>@UtilityService.GetSourceNameById(item.SourceId)</td>
                            <td>@UtilityService.GetCategoryNameById(item.CategoryId)</td>

                            <td><img src="/Content/FeedImages/@item.ImageURL1" height="70px" width="70px" /></td>
                            <td>@item.SourceLink</td>
                            <td>
                                @Html.ActionLink("Edit", "FeedPostEdit", new { id = item.FeedPostId }) |
                                @Html.ActionLink("Delete", "FeedPostDelete", new { id = item.FeedPostId }) |

                                <a href="javascript:void(0)" class="upcomingLink" data-id="@item.FeedPostId">
                                    @if (item.IsUpcoming)
                                    {
                                        <text> Cancel Upcoming </text>
                                    }
                                    else
                                    {
                                        <text> Make Upcoming </text>
                                    }
                                </a>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
</div>


<script type="text/javascript">
    $(".upcomingLink").live("click", function () {
        var id = $(this).attr("data-id");
        var url = "/SuperAdmin/UpdateUpcoming?feedpostid=" + id;
        $.post(url, function(data) {
            $(".feedlistTable").html(data);
        });
    });


    $(".generateFeeds").live("click", function() {
            $.blockUI({
                message: 'Generating Feeds..',
                css: {
                    border: 'none',
                    padding: '15px',
                    backgroundColor: '#fff',
                    '-webkit-border-radius': '10px',
                    '-moz-border-radius': '10px',
                    color: '#000',
                    baseZ: '1051'

                }
            });
            var url = "/SuperAdmin/GenerateFeeds/";
        $.post(url, function() {

        });

    });
</script>